import json
import requests


def get_btcScan_data(tx_hash):
    # 交易网站的网址
    # url=f'https://btcscan.org/api/tx/{tx_hash}'
    url=f'https://api.blockchair.com/bitcoin/dashboards/transaction/{tx_hash}'
    headers = {
            'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0'
        }
    response = requests.get(url=url,headers=headers)

    if response.status_code == 200:
        print("BTC链数据爬取完成！")
        # json_data = json.dumps(response.json(), indent=4)
        # with open('../data/btcdata.json', 'w', encoding='utf-8') as f:
        #     f.write(json_data)
        return response.json()
    else:

        print(f"Error: {response.status_code}, {response.text}")
# get_btcScan_data("DD256E3CEA4E3A542D3D1B384A1A3B727D71EDE5F39D23410762B979F395F771")
